#include <iostream>
#include <cmath>
#include <unordered_map>

bool is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(std::sqrt(num)) + 1; i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

void closest_prime_number(std::string word1, std::string word2, std::string word3) {
    std::unordered_map<std::string, int> numbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    int number = numbers[word1] * 100 + numbers[word2] * 10 + numbers[word3];

    if (100 <= number && number <= 999 && is_prime(number)) {
        std::cout << number << std::endl;
        return;
    }

    while (true) {
        number += 1;
        if (is_prime(number)) {
            std::cout << number << std::endl;
            return;
        }

        number -= 2;
        if (is_prime(number)) {
            std::cout << number << std::endl;
            return;
        }
    }
}

int main() {
    std::string words[3];
    for (int i = 0; i < 3; i++) {
        std::cin >> words[i];
    }
    closest_prime_number(words[0], words[1], words[2]);
    return 0;
}
